package com.songlanyun.common.utils;

import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

@Data
@Component
public class Send {
    @Value("${sms.appkey}")
    private String appKey;

    @Value("${sms.url}")
    private String smsUrl = "";

    @Autowired
    RestTemplate restTemplate;

    public Send() {
    }

    public boolean send(String mobile, String content) {
        String result = null;
        String url = smsUrl + "?mobile=" + mobile + "&content=" + content + "&appkey=" + appKey;
        try {
            result = restTemplate.getForObject(url, String.class);
            JSONObject json = JSONObject.parseObject(result);
            if (json.getInteger("status") != 0) {
                return false;
            } else {
                return true;
            }
        } catch (Exception e) {
            return false;
        }
    }
}